package servlet;

import com.ncist.dao.UserDao;
import com.ncist.pojo.User;
import com.ncist.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@WebServlet("/register")
public class registerServlet extends HttpServlet {
        SqlSession sqlSession;
        @Override
        public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String user;
        sqlSession = MybatisUtils.getSqlSession();
        UserDao mapper = sqlSession.getMapper(UserDao.class);

        String name = request.getParameter("user");
        String pwd = request.getParameter("pass");
         user = mapper.addUser(name,pwd);
        System.out.println("注册成功");
        //第一步：获得sqlSession对象
        //第二步:获得Mapper接口的代理对象
        //第三步:执行方法
        //关闭sqlSession
        sqlSession.close();
        response.sendRedirect("index1.jsp");

        }
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
        }
        }
